import React, {PropTypes} from 'react'
import {Modal, Button} from 'antd'
import BoxLabel from './boxLabel'
import FileUpload from './fileUpload'

const AddFileModal = React.createClass({
  getInitialState(){
    return{
      keyFile: [],
      otherFile: [],
    }
  },
  handleOk(){
    const {keyFile, otherFile} = this.state;
    this.props.onOk(keyFile.concat(otherFile));
  },
  render(){
    let self = this;
    const {visible, onCancel, modalKey, entityName, entityValue, title} = this.props;
    const modalOpts = {
      title: title,
      visible: visible,
      onCancel: onCancel,
      footer: [
        <Button key={'0'} size="large" onClick={self.handleOk}>取消</Button>,
        <Button key={'1'} size="large" type='primary' onClick={self.handleOk}>确定</Button>
      ],
    };

    const fileUploadProps = {
      accept: 'doc|docx|xls|xlsx',//类型限制
      getList: (list, index) => {
        console.log(JSON.stringify(list));
        let ids = [];
        for (let i = 0; i < list.length; i++) {
          ids.push(list[i].response.fId);
        }
        if (index == 0) {
          self.setState({keyFile: ids})
        } else {
          self.setState({otherFile: ids})
        }
      }
    };

    return (
      <Modal {...modalOpts} width={800} key={modalKey}>
        {/*<p style={{fontSize:'18px'}}>{entityName}</p>
        <p style={{fontSize:'16px'}}>{entityValue}</p>
        <div className="splitLine"></div>
        <BoxLabel text="上传附件"/>*/}
        <FileUpload {...fileUploadProps} countLimit={1} labelText="补充汇报材料" index="0"/>
        <FileUpload {...fileUploadProps} labelText="其他附件" index="1"/>
      </Modal>
    )
  }
});

AddFileModal.propTypes = {
  visible: PropTypes.any,
  footer: PropTypes.Array,
  onCancel: PropTypes.func,
  onOk: PropTypes.func,
};

export default AddFileModal
